﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using DBLayer;

namespace BALayer
{
    public class DBDiem
    {
        DAL db = null;
        public DBDiem()
        {
            db = new DAL();
        }
        //Lay Diem
        public DataSet LayDiem()
        {
            return db.ExecuteQueryDataSet("Select * From Diem", CommandType.Text, null);
        }
        //Them Diem
        public bool ThemDiem(ref string err, string MaHS, string MaMH, string MaGV, string MaLop, DateTime NgayKT, string HTKT, float Diem)
        {
            return db.MyExecuteNonQuery("SpThemDiem", CommandType.StoredProcedure, ref err,
                new SqlParameter("@MaHS", MaHS),
                new SqlParameter("@MaMH", MaMH),
                new SqlParameter("@MaGV", MaGV),
                new SqlParameter("@MaLop", MaLop),
                new SqlParameter("@NgayKT", NgayKT),
                new SqlParameter("@HTKT", HTKT),
                new SqlParameter("@Diem", Diem));
        }
        //Xoa Diem
        public bool XoaDiem(ref string err, string MaHS, string MaMH)
        {
            return db.MyExecuteNonQuery("SpXoaDiem", CommandType.StoredProcedure, ref err,
                new SqlParameter("@MaHS", MaHS),
                new SqlParameter("@MaMH", MaMH));
        }
        //Cap Nhat Diem
        public bool CapNhatDiem(ref string err, string MaHS, string MaMH, string MaGV, string MaLop, DateTime NgayKT, string HTKT, float Diem)
        {
            return db.MyExecuteNonQuery("SpCapNhatDiem", CommandType.StoredProcedure, ref err,
                new SqlParameter("@MaHS", MaHS),
                new SqlParameter("@MaMH", MaMH),
                new SqlParameter("@MaGV", MaGV),
                new SqlParameter("@MaLop", MaLop),
                new SqlParameter("@NgayKT", NgayKT),
                new SqlParameter("@HTKT", HTKT),
                new SqlParameter("@Diem", Diem));
        }
        //Tinh Diem TB
        public DataSet TinhDiemTB()
        {
            return db.ExecuteQueryDataSet("select Diem.MaHS,MaMH,MaGV,MaLop,round((sum(Diem*HeSo)/Sum(HeSo)),2) as DiemTB from Diem,HinhThucKiemTra where Diem.MaHTKT=HinhThucKiemTra.MaHTKT group by Diem.MaHS,MaMH,MaGV,MaLop", CommandType.Text, null);
        }

        public bool ThemDiem(ref string err, string p1, string p2, string p3, string p4, DateTime dateTime, string p5, string p6)
        {
            throw new NotImplementedException();
        }

        public bool CapNhatDiem(ref string err, string p1, string p2, string p3, string p4, DateTime dateTime, string p5, string p6)
        {
            throw new NotImplementedException();
        }
    }
}
